Skip to content

Button improvements - #79

Closed
Petethegoat wants to merge 2 commits into
annulusgames:mainfrom
Petethegoat:button_improvements
Closed

Button improvements#79
Petethegoat wants to merge 2 commits into
annulusgames:mainfrom
Petethegoat:button_improvements

Conversation

@Petethegoat

@Petethegoat Petethegoat commented Mar 26, 2024

Copy link
Copy Markdown

Pretty prints method name with ObjectNames.NicifyVariableName(), and adds the method signature as a tooltip:
image

[Button]
void reticulateSplines() {
	Debug.Log("Reticulating splines...");
}

Allows displaying a button with parameters as a simple button instead:
image
This will use default parameters when those are specified in the method signature.

[Button(useParameters: false)]
void PerformAction(string ignorableParam, int number = 100) {
	Debug.Log($"{number} {ignorableParam}s.");
}

Also fills default parameters when specified, for the normal invocation foldout:
image

[Button]
void MoreMethod(int numberOfFoos = 50) {
	Debug.Log($"FooAmount: {numberOfFoos}");
}

Some other areas I'd like to improve and may get to:

  • Selecting different size buttons (increase button height and font size)
  • Making the placement of buttons in the inspector more intuitive - they currently will always display before any TabGroup or FoldoutGroup fields, which usually feels weird. Trying to put them inside those groups will also affect the layout unpredictably. See Inspector element order is unpredictable with PropertyGroups #80

I haven't tested this extremely thoroughly yet, and obviously there should be a documentation update alongside these changes.

Also add tooltip with the method signature, pretty print the method name
( doThing() -> Do Thing ), and make method buttons that do have parameters use any default parameters in the invocation foldout too.
@Petethegoat

Copy link
Copy Markdown
Author

Remade the pull request with only the intended commit.

@Petethegoat

Copy link
Copy Markdown
Author

Do let me know if I can provide anything to help get this merged. Happy to update docs for it if you find the features useful.

@paq

paq commented Jul 28, 2026

Copy link
Copy Markdown
Collaborator

Thanks again for this contribution, and I’m sorry this PR also went without a decision for so long.

I understand the appeal of invoking a parameterized method as a simple button using its default values. It is a useful idea, but I’m concerned that adding another invocation mode to [Button] would increase the complexity of both the API and its behavior.

Where possible, I would prefer to solve this using Alchemy’s existing building blocks. For example, optional inputs can be represented as non-serialized Inspector fields while the button method itself remains parameterless:

[NonSerialized, ShowInInspector]
[LabelText("Specify Number of Foos")]
bool specifyNumberOfFoos;

[NonSerialized, ShowInInspector]
[ShowIf(nameof(specifyNumberOfFoos))]
[LabelText("Number of Foos")]
int numberOfFoos;

[Button]
[LabelText("More Method")]
void MoreMethod()
{
    var value = specifyNumberOfFoos ? numberOfFoos : 50;
    Debug.Log($"FooAmount: {value}");
}

Although this requires a little more code, it makes the behavior explicit and allows existing attributes such as [LabelText], [ShowIf], and grouping or validation attributes to be applied independently to each input. I think that flexibility is more valuable than adding a special parameter-hiding mode to [Button].

I can also see the convenience of generating a readable label with ObjectNames.NicifyVariableName. However, Alchemy is intended to support everyone working in Unity projects, not only programmers. For artists and designers, the internal method name and signature are implementation details rather than useful UI information. An explicitly chosen label through [LabelText] communicates the purpose of the action more clearly and gives the component author control over what users see.

The remaining improvement - initializing parameter fields from their declared default values is useful, but equivalent behavior has since been implemented on the current main branch, so I’m going to close this PR as part of the current maintenance cleanup.

Thanks again for taking the time to propose and implement these improvements.

@paq paq closed this Jul 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants